package org.opens.websocket;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.opens.listener.RedisListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 功能描述
 *
 * @author: zhangyuming
 * @date: 2023/7/10 15:29
 */
@Slf4j
@Component(SimpleWebsocket.REDIS_TOPIC_HANDLE_NAME)
public class WebsocketHandle implements RedisListener {

    @Autowired
    private SimpleWebsocket simpleWebsocket;

    @Override
    public void onMessage(Map<String, Object> paramMap) {
        log.info("【Redis发布订阅模式】redis Listener: {}，参数：{}",simpleWebsocket.REDIS_TOPIC_HANDLE_NAME, paramMap.toString());

        String userId = StrUtil.toString(paramMap.get("userId"));
        String message = StrUtil.toString(paramMap.get("message"));
        if (ObjectUtil.isNotEmpty(userId)) {
            //pc端消息推送具体人
            simpleWebsocket.pushMessage(userId, message);
            //app端消息推送具体人
            //simpleWebsocket.pushMessage(userId+CommonSendStatus.APP_SESSION_SUFFIX, message);
        } else {
            //推送全部
            //simpleWebsocket.pushMessage(message);
        }
    }

}
